package com.sc.nft.controller;

import cn.hutool.core.util.ObjectUtil;
import com.sc.nft.annotation.UserLogin;
import com.sc.nft.controller.request.IdRequest;
import com.sc.nft.dao.UserCollectionDao;
import com.sc.nft.entity.DaoIdentity;
import com.sc.nft.entity.vo.UserAddCatenaCertificateVO;
import com.sc.nft.pool.UserPool;
import com.sc.nft.service.CatenaCertificateService;
import com.sc.nft.service.ImGroupService;
import com.sc.nft.service.UserCollectionService;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/userCreatorInfo")
@Api(tags = "用户dao")
public class UserGroupController {

    private final CatenaCertificateService catenaCertificateService;

    private final ImGroupService imGroupService;
    private final UserCollectionService userCollectionService;

    @ApiOperation(value = "用户是否在某个组下", notes = "用户是否在某个组下", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @PostMapping(value = "/userIsExistGroup", produces = MediaType.APPLICATION_JSON_VALUE)
    @UserLogin
    public Result userIsExistGroup(@Validated @RequestBody IdRequest idRequest) {
        Map map = new HashedMap();
        map.put("isExist", catenaCertificateService.userIsExistGroup(UserPool.getUser(), idRequest.getId()));
        // 这个组下有没有聊天群
        map.put("groupIsExist", imGroupService.groupIsExist(idRequest.getId()));
        DaoIdentity daoIdentity = userCollectionService.getDaoIdentityName(idRequest.getId());
        map.put("identityName", ObjectUtil.isNull(daoIdentity) ? "" : daoIdentity.getIdentityName());
        map.put("identityId", ObjectUtil.isNull(daoIdentity) ? "" : daoIdentity.getId());
        return Result.success(map);
    }


}
